﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;

namespace weighing
{
   public class InptrHelper
    {
        /// <summary>
        /// WPF下取得控件的句柄
        /// </summary>
        /// <param name="uielement"></param>
        /// <returns></returns>
        public static IntPtr GetControlHandle(UIElement uielement)
        {
            PresentationSource ps = PresentationSource.FromVisual(uielement);
            IntPtr hwnd = ((HwndSource)ps).Handle;
            return hwnd;
        }
        /// <summary>
        /// WPF下取得窗口的句柄
        /// </summary>
        /// <param name="win"></param>
        /// <returns></returns>
        public static IntPtr GetWindowHandle(Window win)
        {
            IntPtr hwnd = new WindowInteropHelper(win).Handle;
            return hwnd;
        }
    }
}
